import axios from '@/utils/request.js'
// import store from '@/store'

// 登录注册 -- 注册
export const userRegAPI = ({ username, password, repassword }) =>
  axios({
    url: '/api/reg',
    method: 'POST',
    data: {
      username,
      password,
      repassword
    }
  })

// 登录注册 -- 登录
export const userLoginAPI = ({ username, password }) =>
  axios({
    url: '/api/login',
    method: 'POST',
    data: {
      username,
      password
    }
  })

// 布局 -- 获取侧边栏数据
export const getMenusInfoAPI = () =>
  axios({
    url: '/my/menus',
    method: 'GET'
  })

// 用户 -- 获取用户基本资料
export const getUserInfoAPI = () =>
  axios({
    url: '/my/userinfo',
    method: 'GET'
  })

// 用户 -- 更新用户基本资料
export const updateUserInfoAPI = ({ id, nickname, email }) =>
  axios({
    url: '/my/userinfo',
    method: 'PUT',
    data: {
      id,
      nickname,
      email
    }
  })

// 用户 -- 更新用户头像
export const updateUserAvatarAPI = ({ avatar }) =>
  axios({
    url: '/my/update/avatar',
    method: 'PATCH',
    data: {
      avatar
    }
  })

// 用户 -- 更新用户密码
export const updatePwdAPI = ({ old_pwd, new_pwd, re_pwd }) =>
  axios({
    url: '/my/updatepwd',
    method: 'PATCH',
    data: {
      old_pwd,
      new_pwd,
      re_pwd
    }
  })

// 文章分类 -- 获取文章分类
export const getArtListAPI = () =>
  axios({
    url: '/my/cate/list',
    method: 'GET'
  })

// 文章分类 -- 增加文章分类
export const addArtListAPI = ({ cate_name, cate_alias }) =>
  axios({
    url: '/my/cate/add',
    method: 'POST',
    data: {
      cate_name,
      cate_alias
    }
  })

// 文章分类 -- 删除文章分类
export const removeArtListAPI = ({ id }) =>
  axios({
    url: '/my/cate/del',
    method: 'DELETE',
    params: {
      id
    }
  })

// 文章分类 -- 更新文章分类
export const updateArtListAPI = ({ id, cate_name, cate_alias }) =>
  axios({
    url: '/my/cate/info',
    method: 'PUT',
    data: {
      id,
      cate_name,
      cate_alias
    }
  })

// 文章管理 -- 发布文章
export const addArticleAPI = (fd) =>
  axios({
    url: '/my/article/add',
    method: 'POST',
    data: fd
  })

// 文章管理 -- 获取文章列表
export const getArticleAPI = ({ pagenum = 1, pagesize = 5, cate_id, state }) =>
  axios({
    url: '/my/article/list',
    method: 'GET',
    params: {
      pagenum,
      pagesize,
      cate_id,
      state
    }
  })

// 文章管理 -- 获取文章详情
export const getArtInfoAPI = ({ id }) =>
  axios({
    url: '/my/article/info',
    method: 'GET',
    params: {
      id
    }
  })

// 文章管理 -- 删除文章详情
export const delArtInfoAPI = ({ id }) =>
  axios({
    url: '/my/article/info',
    method: 'DELETE',
    params: {
      id
    }
  })
